﻿@using TBM.Models
@using System.Text
@{
	List<ModuleController> Controllers = (List<ModuleController>) ViewBag.Controllers;
}
@functions {
	string GetChildren (List<ModuleItem> children){
		if(children == null){
			return "";
		}

		int cnt = children.Count;
		StringBuilder sjs =  new StringBuilder(", 'children': [");

		for(int i = 0; i < cnt; i++){
			sjs.Append("{");
			sjs.AppendFormat("'id': {0}", children[i].ID);
			sjs.AppendFormat(", 'text': '{0}'", children[i].ActionDescr);
			sjs.Append(", 'icon': 'fa fa-cube'");
			sjs.Append(", 'state' : { 'opened' : true, 'selected' : " + (children[i].IsActived ? "true" : "false") + " }");
			sjs.Append(GetChildren(children[i].SubModule));
			sjs.Append("}");

			if(i < cnt - 1){
				sjs.Append(",");
			}
		}

		sjs.Append("]");

		return sjs.ToString();
	}
}
<div class="alert alert-warning">
    勾选的模块将会加入权限验证，否则视为不验证该模块的权限。
</div>
<form id="moduleForm" action="~/System/UpdateModule">
	<div id="modules"></div>
	<div class="mt-30">
		<button id="btnSaveModule" class="btn blue">			<i class="fa fa-save"></i> 保存配置		</button>
	</div>
</form>

<script type="text/javascript">
	var data = [
	@{
		int count = Controllers.Count;
		StringBuilder js =  new StringBuilder();

		for(int i = 0; i < count; i++){
			ModuleController c = Controllers[i];
			js.Append("{");
			js.AppendFormat("'text': '{0}'", c.ControllerDescr);
			js.Append(", 'icon': 'fa fa-cubes'");
			js.Append(", 'state' : { 'opened' : true }");
			js.Append(GetChildren(c.SubModule));
			js.Append("}");

			if(i < count - 1){
				js.Append(",");
			}
		}

		@Html.Raw(js.ToString())
	}
	];

    System.initMoudle(data);
</script>